package game.utils
{
	public class LightUtils
	{
		public static const RED:uint 		= 0xFF0000;
		public static const BLUE:uint 		= 0x0000FF;
		public static const NONE:uint 		= 0x000000;
		public static const GREEN:uint 		= 0x00FF00;
		public static const WHITE:uint 		= 0xFFFFFF;
		public static const YELLOW:uint 	= 0xFFFF00;
		public static const ORANGE:uint 	= 0xFF6600;
		public static const PURPLE:uint 	= 0xFF00FF;
		
		public static const TYPES:Array 	= [RED, BLUE, NONE, GREEN, WHITE, YELLOW, ORANGE, PURPLE];
		
		public static function add(color1:uint, color2:uint):uint
		{
			switch(color1)
			{
				case NONE: 	return color2;
				case WHITE: return color1;
				
				case RED:
					switch(color2)
					{
						case RED: case NONE:
							return RED;
						case BLUE: case PURPLE:
							return PURPLE;
						case YELLOW: case ORANGE:
							return ORANGE;
						case GREEN: case WHITE:
							return WHITE;
					}
					break;
				
				case BLUE:
					switch(color2)
					{
						case RED: case PURPLE:
							return PURPLE;
						case BLUE: case NONE:
							return BLUE;
						case GREEN: case YELLOW:
							return GREEN;
						case ORANGE: case WHITE:
							return WHITE;
					}
					break;
				
				case YELLOW:
					switch(color2)
					{
						case RED: case ORANGE:
							return ORANGE;
						case BLUE: case GREEN:
							return GREEN;
						case NONE: case YELLOW:
							return YELLOW;
						case PURPLE: case WHITE:
							return WHITE;
					}
					break;
				
				case GREEN:
					switch(color2)
					{
						case BLUE: case NONE: case GREEN: case YELLOW:
							return GREEN;
						case RED: case WHITE: case ORANGE: case PURPLE:
							return WHITE;
					}
					break;
				
				case ORANGE:
					switch(color2)
					{
						case RED: case NONE: case YELLOW: case ORANGE:
							return ORANGE;
						case BLUE: case GREEN: case WHITE: case PURPLE:
							return WHITE;
					}
					break;
				
				case PURPLE:
					switch(color2)
					{
						case RED: case BLUE: case NONE: case PURPLE:
							return PURPLE;
						case GREEN: case YELLOW: case WHITE: case ORANGE:
							return WHITE;
					}
					break;
			}
		}
		
		public static function subtract(color1:uint, color2:uint):uint
		{	
			switch(color1)
			{
				case NONE:				return color1;
					
				case WHITE:
					switch(color2)
					{
						case RED: 		return GREEN;
						case BLUE: 		return ORANGE;
						case NONE: 		return WHITE;
						case GREEN: 	return RED;
						case WHITE: 	return NONE;
						case ORANGE: 	return BLUE;
						case PURPLE: 	return YELLOW;
						case YELLOW: 	return PURPLE;
					}
					break;
				case GREEN:
					switch(color2)
					{
						case RED: 		case NONE:		return GREEN;
						case BLUE: 		case PURPLE:	return YELLOW;
						case GREEN: 	case WHITE:		return NONE;
						case YELLOW: 	case ORANGE:	return BLUE;
					}
					break;
				case ORANGE:
					switch(color2)
					{
						case RED: 		case PURPLE:	return YELLOW;
						case GREEN: 	case YELLOW:	return RED;
						case ORANGE: 	case WHITE:		return NONE;
						case NONE: 		case BLUE:		return ORANGE;
					}
					break;
				case PURPLE:
					switch(color2)
					{
						
						case RED: 		case ORANGE:	return BLUE;
						case BLUE: 		case GREEN:		return RED;
						case PURPLE:	case WHITE:		return NONE;
						case YELLOW:	case NONE:		return PURPLE;
					}
					break;
				default: return NONE;
			}
		}
		
		public static function isLightColor(color:uint):Boolean
		{
			for(var i:uint = 0; i < TYPES.length; i++)
				if(color == TYPES[i]) return true;
			
			return false;
		}
	}
}